define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'deerhome/shop_apply/index' + location.search,
                    add_url: 'deerhome/shop_apply/add',
                    edit_url: 'deerhome/shop_apply/edit',
                    del_url: 'deerhome/shop_apply/del',
                    multi_url: 'deerhome/shop_apply/multi',
                    import_url: 'deerhome/shop_apply/import',
                    table: 'deerhome_shop_apply',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'deerhome_user_id', title: __('用户UID')},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')}, formatter: Table.api.formatter.label},
                        {field: 'mdname', title: __('Mdname'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'latitude', title: __('Latitude'), operate: 'LIKE'},
                        {field: 'longitude', title: __('Longitude'), operate: 'LIKE'},
                        {field: 'user_name', title: __('User_name'), operate: 'LIKE'},
                        {field: 'user_tel', title: __('User_tel'), operate: 'LIKE'},
                        {field: 'sfz', title: __('Sfz'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'sfz_a_image', title: __('Sfz_a_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'sfz_b_image', title: __('Sfz_b_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'yyzz_image', title: __('Yyzz_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'city', title: __('City'), operate: 'LIKE'},
                        {field: 'area', title: __('区域'), operate: 'LIKE'},
                        {field: 'note', title: __('Note'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'add_time', title: __('Add_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'sh_user', title: __('Sh_user'), operate: 'LIKE'},
                        // {field: 'sh_note', title: __('Sh_note'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'sh_time', title: __('Sh_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.buttons,buttons: [
                            {
                                name: 'sh_ok',
                                text: __('审核通过'),
                                title: __('审核通过'),
                                classname: 'btn btn-xs btn-success btn-ajax',
                                url: 'deerhome/shop_apply/sh?status=2&id={ids}',
                                confirm:function(r){
                                    return '是否确定通过'+r.user_name+'？';
                                },
                                refresh: true,
                                visible: function (row) {
                                    return row.status==1;
                                }
                            },
                            {
                                name: 'sh_no',
                                text: __('拒绝'),
                                title: __('拒绝'),
                                classname: 'btn btn-xs btn-danger btn-ajax',
                                url: 'deerhome/shop_apply/sh?status=3&id={ids}',
                                confirm:function(r){
                                    return '是否确定拒绝'+r.user_name+'？';
                                },
                                refresh: true,
                                visible: function (row) {
                                    return row.status==1;
                                }
                            }
                        ]}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
